<template>
  <div id="login-form" style="padding-bottom: 3%"></div>
</template>

<script>
import { ManagementClient } from 'authing-js-sdk';
export default {
  data() {
    return {
      model: { manufacturer: { name: "", _id: "" } },
      dialogVisible: true,
    };
  },
  mounted() {
    //
    this.$store.state.showLogin = false;
    const appId = "";
    // Authing 用户池 ID
    const userPoolId = "5fbb40ea49d4b5f780e81fe0";
    const userSecret = "e6b0933959f9b6386bf0660b0438fec3";
    const domain = "https://my-app-work-network-developing.authing.cn";

    const form = new Guard(userPoolId, {
      title: "网上商城",
      mountId: "login-form",
      hideClose: true,
    });

    const that = this;

    form.on("authenticated", async (userInfo) => {
      localStorage.clear();
      that.$store.commit("SET_USER", userInfo);
      const managementClient = new ManagementClient({
        userPoolId: userPoolId,
        secret: userSecret,
      });
      localStorage.setItem("token", JSON.stringify(userInfo.token));
      localStorage.setItem("userInfo", JSON.stringify(userInfo));
      const { list } = await managementClient.users.listRoles(userInfo._id);
      console.log(list);
      localStorage.setItem("userAccess", JSON.stringify(list));

      that.$router.push("/");
    });
  },
};
</script>
